//

// (  )
//

package com.tools.acceleratecore.xlib.util;

import android.text.TextUtils;

public class UtilRoot {
    private static UtilRoot.IRootCommand sIRootCommand = null;

    public UtilRoot() {
    }

    public static void setDefaultRoot() {
        if (sIRootCommand == null) {
            sIRootCommand = new RootCommand();
        }
    }

    public static void setRoot(UtilRoot.IRootCommand iRootCommand) {
        sIRootCommand = iRootCommand;
    }

    public static boolean checkRoot() {
        return sIRootCommand == null ? false : sIRootCommand.checkRoot();
    }

    public static String doCommand(String strCmd) {
        return sIRootCommand != null && checkRoot() && !TextUtils.isEmpty(strCmd) ? sIRootCommand.doCommand(strCmd) : null;
    }

    public static void echo(String strFileName, String strContent) {
        if (!TextUtils.isEmpty(strFileName) && !TextUtils.isEmpty(strContent)) {
            String strCmd = String.format("echo \"%s\" > %s", strContent, strFileName);
            doCommand(strCmd);
        }
    }

    public interface IRootCommand {
        boolean checkRoot();

        String doCommand(String var1);
    }
}
